﻿package mortal.game.view.battle
{
    import Message.Public.*;
    import extend.language.*;
    import flash.text.*;
    import flash.utils.*;
    import mortal.common.*;
    import mortal.common.font.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.scene3D.map3D.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;

    public class BattleStartCDView extends View
    {
        private var _tfCutDown:SecTimerView;
        private var _battleLeftTimeView:LeftTimeView;
        private var _battleStart:SBattleStart;
        private static var _instance:BattleStartCDView;

        public function BattleStartCDView()
        {
            this.layer = LayerManager.uiLayer;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            return;
        }// end function

        public function clearObj() : void
        {
            if (this._battleLeftTimeView)
            {
                this._battleLeftTimeView.hide();
                this._battleLeftTimeView = null;
            }
            if (this._tfCutDown)
            {
                this._tfCutDown.removeEventListener(EventName.SecViewTimeChange, this.onChange);
                this._tfCutDown.dispose();
                this._tfCutDown = null;
            }
            this._tfCutDown = null;
            return;
        }// end function

        public function updateBattleStart(param1:SBattleStart) : void
        {
            var _loc_2:TextFormat = null;
            this._battleStart = param1;
            if (!this._tfCutDown)
            {
                _loc_2 = new GTextFormat(FontUtil.EmbedNumberName, 100, 16711680);
                this._tfCutDown = new SecTimerView();
                this._tfCutDown.width = 200;
                this._tfCutDown.height = 200;
                this._tfCutDown.mouseEnabled = false;
                this._tfCutDown.embedFonts = true;
                this._tfCutDown.defaultTextFormat = _loc_2;
                this._tfCutDown.addEventListener(EventName.SecViewTimeChange, this.onChange);
                this.addChild(this._tfCutDown);
            }
            this._tfCutDown.setParse("s");
            this._tfCutDown.setLeftTime(this._battleStart.waitTime);
            return;
        }// end function

        private function onChange(event:DataEvent) : void
        {
            var _loc_2:* = int(event.data);
            if (_loc_2 > 0)
            {
                this._tfCutDown.text = event.data.toString();
            }
            else if (_loc_2 == 0)
            {
                this._tfCutDown.text = "";
                setTimeout(hide, 1000);
                if (!this._battleLeftTimeView)
                {
                    this._battleLeftTimeView = new LeftTimeView(Language.getString(11209));
                }
                this._battleLeftTimeView.show();
                this._battleLeftTimeView.updateLeftTime(this._battleStart.continueTime);
            }
            return;
        }// end function

        override public function stageResize() : void
        {
            this.x = (SceneRange.display.width - 100) / 2;
            this.y = (SceneRange.display.height - 460) / 2;
            return;
        }// end function

        public static function get instance() : BattleStartCDView
        {
            if (!_instance)
            {
                _instance = new BattleStartCDView;
            }
            return _instance;
        }// end function

    }
}
